<!DOCTYPE HTML>
<html lang="en-US">

<head>
    <meta charset="UTF-8">
    <title>ueditor demo</title>
</head>

    <body>
    <input id="avatar" name="upload" type="file" class="header_img"/>
    <img id="avatar-src" src=""/>
    <input type="button" id="butn" onclick="shanchuan()" value="上传"/>
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script type="text/javascript">
        //实名上传,头像上传
        function avatarImg(imgSrc, addUpload) {
            var formData = new FormData();
            formData.append('file', imgSrc); //将文件转成二进制形式
            $.ajax({
                type: "post",
                url: "localhost:8888/uploadFile/uploadCross?type=code",
                async: false,
                contentType: false, //这个一定要写
                processData: false, //这个也一定要写，不然会报错
                data: formData,
                dataType: 'text', //返回类型，有json，text，HTML。这里并没有jsonp格式，所以别妄想能用jsonp做跨域了。
                success: function (data) {
                    var src = "d:/tmp/" + data;
                    alert(src)
                    addUpload.attr('src', src);
                    addUpload.attr('data-src', data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown, data) {
                    console.log(errorThrown);
                }
            });
        }

        function shanchuan() {
            var imgSrc = $("#avatar")[0].files[0];
            avatarImg(imgSrc, $('#avatar-src'));
        }
    </script>
    </body>

</html>